/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package icl.exercise.map;

import icl.exercise.R;
import icl.exercise.utilities.FileUtilities;

import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

/**
 * Example of how to use an {@link com.google.android.maps.MapView}. <h3>
 * MapViewDemo</h3>
 *
 * <p>
 * This demonstrates creating a Map based Activity.
 * </p>
 *
 * <h4>Demo</h4> Views/MapView
 *
 * <h4>Source files</h4>
 * <table class="LinkTable">
 * <tr>
 * <td >src/com.example.android.apis/view/MapViewDemo.java</td>
 * <td >The Alert Dialog Samples implementation</td>
 * </tr>
 * <tr>
 * <td >/res/layout/mapview.xml</td>
 * <td >Defines contents of the screen</td>
 * </tr>
 * </table>
 */
public class MapViewActivity extends MapActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mapview);

		MapView mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);

		Bundle extras = this.getIntent().getExtras();
		final String fLat = extras.getString("fromLat");
		final String fLong = extras.getString("fromLong");

		List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(
				R.drawable.androidmarker);
		MyMapMarker itemizedoverlay = new MyMapMarker(drawable);

		List<GeoPoint> locs = FileUtilities.GetGPSLocations();

		GeoPoint point = new GeoPoint(19240000, -99120000);
		OverlayItem overlayitem = new OverlayItem(locs.get(1), "Hola, Mundo!",
				"I'm in Mexico City!");

		CreatePathOverlay(mapOverlays);

		// itemizedoverlay.addOverlay(overlayitem);

		// mapOverlays.add(itemizedoverlay);
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	private void CreatePathOverlay(List<Overlay> mapOverlays) {
		List<GeoPoint> locs = FileUtilities.GetGPSLocations();

		for (int i = 1; i < locs.size(); i++) {
			mapOverlays.add(new PathOverlay(locs.get(i - 1), locs.get(i)));
		}

	}

}
